home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / MPW Oberon 2.1168 / OInterfaces / Disassembler.mod < prev    next >
Encoding:
Text File  |  1995-08-10  |  26.0 KB  |  465 lines  |  [TEXT/MPS ]

  1. (**---------------------------------------------------------------------------*
  2.  |                                                                           |
  3.  |                          <<< Disassembler.p >>>                           |
  4.  |                                                                           |
  5.  |                     Power[PC] Disassembler Interfaces                     |
  6.  |                                                                           |
  7.  |                               Ira L. Ruben                                |
  8.  |                                  5/9/93                                   |
  9.  |                                                                                                                                                     |
  10.  |                                        Translated from C to Pascal by                                                 |
  11.  |                                                             Greg Branche                                                                 |
  12.  |                                                                 7/20/94                                                                     |
  13.  |                                                                           |
  14.  |                  Copyright Apple Computer, Inc. 1993-1995                 |
  15.  |                           All rights reserved.                            |
  16.  |                                                                           |
  17.  *---------------------------------------------------------------------------**)
  18.  
  19. (*$TAGS-*)
  20. (*$CALLING PASCAL*)
  21. MODULE Disassembler;
  22.  
  23. IMPORT SYSTEM, Types;
  24.  
  25. (* $PUSH*)
  26.  
  27. CONST
  28.  
  29. (** The following defines the "options" that can be passed to the disassembler.  All    **)
  30. (** except ONE of the target architecture options have preset defaults.                            **)
  31.  
  32.                                                                                 (** Target architecture (one must be set):        **)
  33.     Disassemble_Power*             = $00000001;        (**    Power                                                                    **)
  34.     Disassemble_PowerPC32*     = $00000002;        (**       32-bitPowerPC                                            **)
  35.     Disassemble_PowerPC64*  = $00000004;        (**          64-bit PowerPC                                     **)
  36.     Disassemble_PowerPC601* = $00000008;        (**             PowerPC 601                                    **)
  37.                                                                                 (** Error detection options*:                         **)
  38.     Disassemble_RsvBitsErr* = $80000000;        (**    invalid reserved bits is error                **)
  39.     Disassemble_FieldErr*     = $40000000;        (**    invalid field (regs, BO, etc.) error    **)
  40.                                                                                 (** Formatting options (reverses presets):        **)
  41.     Disassemble_Extended*     = $08000000;        (**    extended mnemonics (ppc only)                    **)
  42.     Disassemble_BasicComm*     = $04000000;        (**    basic form in comment if extended            **)
  43.     Disassemble_DecSI*             = $02000000;        (**    SI fields formatted as decimal                **)
  44.     Disassemble_DecUI*             = $01000000;        (**    UI fields formatted as decimal                **)
  45.     Disassemble_DecField*     = $00800000;        (**         fields shown as decimal                                **)
  46.     Disassemble_DecOffset*     = $00400000;        (**    D of D(RA) shown in decimal                        **)
  47.     Disassemble_DecPCRel*     = $00200000;        (**    $+decimal offset instead of $+hex            **)
  48.     Disassemble_DollarHex*     = $00100000;        (**    $XXX... instead of 0xXXX...                        **)
  49.     Disassemble_Hex2sComp*     = $00080000;        (**         negative hex shown in 2s compliment        **)
  50.     Disassemble_MinHex*         = $00040000;        (**        min nbr of hex digits for values >= 0    **)
  51.     Disassemble_CRBits*         = $00020000;        (**    crN_LT, crN_GT, crN_EQ, crN_SO                **)
  52.     Disassemble_CRFltBits*  = $00010000;        (**        crN_FX, crN_FEX, crN_VX, crN_OX                **)
  53.     Disassemble_BranchBO*     = $00008000;        (**        branch BO meaning if not extended            **)
  54.     Disassemble_TrapTO*          = $00004000;        (**        trap TO meaning if not extended                **)
  55.     Disassemble_IBM*                 = $00002000;        (**    IBM assembler conventions                            **)
  56.  
  57. (**
  58. Except for the target architecture options, ONE of which must be set, here's an explanation
  59. of the other options and their preset default.
  60.      
  61. Disassemble_RsvBitsErr - Reserved bits in PowerPC instructions are considered a "warning"
  62.                                                  and causes the return status to be set to indicate whether
  63.                                                  reserved bits were incorrectly coded (1's that should be 0's and
  64.                                                  vice versa). The option indicates incorrectly coded reserved bits
  65.                                                  cause the instruction to be treated as "invalid".
  66.  
  67. Disassemble_FieldErr     - Attempted use of a field value not valid for a target is
  68.                                                  considered a "warning" and causes the return status to be set to
  69.                                                  indicate that fact.  The option indicates that use of a field
  70.                                                  whose value is not valid for the target is "invalid".  An example
  71.                                                  of an invalid field would be the use of a SPR not supported for
  72.                                                  the target architecture like the "HIDx" SPRs which are only valid
  73.                                                  for the 601.  Another example is non zero bits in the bc[l][a] BO
  74.                                                  field that are supposed to be zero.  Note this is NOT the same as
  75.                                                  Disassemble_RsvBitsErr.  But if a field has NO valid decoding
  76.                                                  value for ANY target, that is always considered as an invalid
  77.                                                  instruction.
  78.  
  79. Disassemble_Extended     - Extended mnemonics are NOT generated.  The option allows the
  80.                                                  extended mnemonic generation (recommended).  Only PowerPC32,
  81.                                                  PowerPC64, and PowerPC32 and PowerPC64 instructions used on the
  82.                                                  601 are supported.
  83.  
  84. Disassemble_BasicComm     - The basic instruction form is NOT placed in the comment field.
  85.                                                  The option causes the basic form of the instruction to be placed
  86.                                                  in the comment if an extended mnemonic is generated for it.  This
  87.                                                  option is not recommended since it is mainly for debugging and it
  88.                                                  tends to "clutter" up the comment field making it harder to see
  89.                                                  branch addresses.
  90.  
  91. Disassemble_DecSI             - SIs (signed immediate integers) are formatted as hex.  The option
  92.                                                  causes SI operands to be generated as decimal integers.
  93.  
  94. Disassemble_DecUI             - UIs (unsigned immediate integers) are formatted as hex.  The
  95.                                                  option causes UI operands to be generated as decimal integers.
  96.  
  97. Disassemble_DecField     - All fields (e.g., shift/rotate constants) are shown as hex.  The
  98.                                                  option causes the offsets to be generated as decimal integers.
  99.  
  100. Disassemble_DecOffset  - The "D" offsets in operands of the form D(RA) are shown in hex.
  101.                                                  The option causes these to be generated as decimal.
  102.  
  103. Disassemble_DecPCRel     - PC-relative branch addresses are formatted as "$+n" or "$-n", with
  104.                                                  the offset ("n") generated in hex.  The option causes the offset
  105.                                                  to be generated as decimal.
  106.  
  107. Disassemble_DollarHex     - Hex values are prefixed with "0x".  The option causes hex values
  108.                                                  to be formatted as "$XXX...".
  109.  
  110. Disassemble_Hex2sComp     - Signed negative values that are shown in hex are negated and
  111.                                                  prefixed with a "-" (e.g. "-0x0001").  The option causes these
  112.                                                  values to be shown in their two's complement form (e.g.,
  113.                                                  "0xFFFFFFFF").
  114.  
  115. Disassemble_MinHex         - Positive hex values or negated negative values are always shown
  116.                                                  with the number of digits attempting to indicate the size of the
  117.                                                  instruction field which produced the value or the implied value
  118.                                                  size.  Thus 32-bit target addresses are shown as 8 hex digits,
  119.                                                  16-bit field values are shown with 4 hex digits, byte field values
  120.                                                  as 2 hex digits.  5 or six-bit values are also shown as 2 hex
  121.                                                  digits since the minimum is always at least 2. The option forces
  122.                                                  the generation to always use 2 as the minimum even if the value
  123.                                                  came from a bigger field (e.g., "0x1234" address, "0x01" or
  124.                                                  "-0x01" from a 16-bit field).
  125.  
  126. Disassemble_CRBits          - Condition register field bits are referenced as bit numbers 0:31
  127.                                                  in the basic instruction operand forms.  The option causes these
  128.                                                  bits to be referenced using the format “crN_X”, where N is a 4-bit
  129.                                                  CR field (0:7) and X is the bit “name” in the field (“LT”, “GT”,
  130.                                                  “EQ”, “SO” for bits 0, 1, 2, and 3 respectively).  Note, this
  131.                                                  notation is always used with extended mnemonics.
  132.  
  133. Disassemble_CRFltBits  - Condition register field bits are referenced as bit numbers 0:31
  134.                                                  in the basic instruction operand forms.  The option is identical
  135.                                                  to Disassemble_CRBits to generate the references as “crN_X”,
  136.                                                  except that the bits (X) are referenced as “FX”, “FEX”, “VX” and
  137.                                                  “OX” for the four bits 0,1, 2, and 3 respectively.  This option
  138.                                                  can be used if the context of floating-point operations, but it's
  139.                                                  up to the caller to determine that context.
  140.  
  141. Disassemble_BranchBO     - Branch test BO encodings are referenced as values 0:31 in the 
  142.                                                  basic instruction operand forms.  The option causes the BO value
  143.                                                  to be referenced as more meaningful names (e.g., "dCTR_NZERO_NOT",
  144.                                                  "ALWAYS", etc.).
  145.                                                  
  146. Disassemble_TrapTO         - Trap TO operand encodings are referenced as values 0:31 in the 
  147.                                                   basic instruction operand forms.  The option causes the TO value
  148.                                                  to be an expression of the form "x|y|...", where the "x", "y",
  149.                                                  and so are the meaning of each of the five TO bits; "LT", "GT",
  150.                                                  "EQ", "LOW", "HI" for bits 0, 1, 2, 3, and 4 respectively.
  151.  
  152. Disassemble_IBM                 - Apple assembler conventions are used for comments and invalid
  153.                                                  instructions.  The option causes IBM assembler conventions to be
  154.                                                  used for these.  A “#” is used instead of a “;” as the comment
  155.                                                  character, and “.long” is used instead of “dc.l” for the invalid
  156.                                                  instruction directive mnemonic.
  157.  
  158.                                   [Are we having fun yet?]
  159. **)
  160.  
  161. (** The following defines a set of the above options which seem to give "acceptable"         **)
  162. (** results*:                                                                                                                                                            **)
  163.  
  164.     DisStdOptions* = (Disassemble_Extended  +            (** permit extended mnemonics                **)
  165.                    Disassemble_DecSI     +            (** decimal SIs but hex UIs                    **)
  166.                    Disassemble_DecField  +            (** decimal field numbers                        **)
  167.                    Disassemble_BranchBO  +            (** meaning of branch BO                            **)
  168.                                      Disassemble_TrapTO         +            (** meaning of trap TO                                **)
  169.                                      Disassemble_CRBits);                    (** CR bits references as crN_X            **)
  170.                                              
  171.  
  172.     (** Return status flags*:                                                                                                                        **)
  173.     
  174.     Disassembler_OK*                      = $0001;        (** instruction successfully decoded                    **)
  175.     Disassembler_InvRsvBits*      = $0002;        (** invalidly coded reserved bits                        **)
  176.     Disassembler_InvField*          = $0004;        (** invalidly coded field(s)                                    **)
  177.     Disassembler_InvSprMaybe*     = $0008;        (** possibly invalid SPR                                            **)
  178.     Disassembler_601Power*             = $0010;        (** power instruction used with 601                    **)
  179.     Disassembler_Privileged*      = $0020;        (** privileged instruction                                        **)
  180.     Disassembler_Optional*          = $0040;        (** optional instruction                                            **)
  181.     Disassembler_Branch*                 = $0080;        (** branch instruction                                                **)
  182.     Disassembler_601SPR*                 = $0100;        (** SPR valid only for 601 has been used            **)
  183.     Disassembler_HasExtended*  = $4000;        (** possible extended mnemonic                                **)
  184.     Disassembler_ExtendedUsed* = $8000;        (** the extended mnemonic was generated            **)
  185.  
  186.     DisInvalid*                                 = $0000;        (**       invalid instruction                                **)
  187.  
  188.     (**
  189.     Unless DisInvalid (0) is returned as the function result, Disassembler_OK will always be
  190.     set.  The other flags have the following meaning*:
  191.     
  192.     Disassembler_InvRsvBits        - The instruction had some or all of its reserved bits
  193.                                                             incorrectly coded, and the Disassemble_RsvBitsErr option was
  194.                                                             NOT set.  This is something like a "warning". With the option
  195.                                                             set, this condition is considered as an "error" and the
  196.                                                             "invalid instruction" is generated ("dc.l 0xXXXXXXXX").
  197.     
  198.     Disassembler_InvField            -    The instruction had fields incorrectly coded for the
  199.                                                             target, but is is still valid for some target (e.g., not
  200.                                                             valid for the 601 but valid for the PowerPC64), and the
  201.                                                             Disassemble_FieldErr option was NOT set.
  202.     
  203.     Disassembler_InvSprMaybe    - A mfspr or mtspr instruction references a POSSIBLY invalid
  204.                                                             SPR.  This occurs when an SPR value is not for one of the
  205.                                                             predefined SPR names (see list above) and there is no lookup
  206.                                                             routine, or it does not supply a substitution name.  In that
  207.                                                             case the SPR register number is generated.  Since there is
  208.                                                             no way of the disassembler knowing whether the register is
  209.                                                             valid for the architecture of interest, this flag is set 
  210.                                                             instead of Disassembler_InvField to indicate the possibility
  211.                                                             that the SPR may be invalid.
  212.     
  213.     Disassembler_601Power            - The options specified that the target architecture is the
  214.                                                             601 (Disassemble_PowerPC601), and a Power instruction was
  215.                                                             disassembled.  The 601 is basically an ORing of the Power
  216.                                                             and PowerPC32 architectures.  But this flag could be useful
  217.                                                             for "weeding" Power instructions out in preparation for use
  218.                                                             on a "pure" PowerPC32 or PowerPC64 architecture.
  219.     
  220.     Disassembler_601SPR                - The options specified that the target architecture is the
  221.                                                             601 (Disassemble_PowerPC601), and a mfspr or mtspr
  222.                                                             instruction references a SPR valid ONLY for the 601.
  223.                                                             
  224.     Disassembler_Privileged        - The instruction is privileged.
  225.                                                             
  226.     Disassembler_Optional            - The instruction is optional.
  227.     
  228.     Disassembler_Branch                -    Branch instruction; bc[l][a], b[l][a], bclr[l], bcctr[l] and
  229.                                                             Power bcr[l], bcc[l].  If any of these instructions are
  230.                                                             processed the flag is set.  Branches are signaled because
  231.                                                             the caller might want to do some additional processing on
  232.                                                             these.  For example, a debugger might want to dynamically
  233.                                                             show which way the branch is taken, or static analysis might
  234.                                                             want to know possible exit points from a function or show
  235.                                                             the branch in some graphical way.  Although the caller could
  236.                                                             determine if the instruction is a branch, the disassembler
  237.                                                             always has to classify the instructions passed to it, so
  238.                                                             there is no sense having both do it if the information is
  239.                                                             already available.  Note, the caller might still, however,
  240.                                                             need to extract the BO and BI fields to determine the
  241.                                                             condition of the branch, but at least it only needs to be
  242.                                                             done when the flag is set.
  243.     
  244.     Disassembler_HasExtended     - The instruction POSSIBLY has an extended mnemonic, whether
  245.                                                             used or not used (as a function of the Disassemble_Extended
  246.                                                             option). Note, "possibly has an extended mnemonic"; the
  247.                                                             instruction could have extendeds, but not for all
  248.                                                             values of its operands.
  249.                                                             
  250.     Disassembler_ExtendedUsed - The instruction has an extended mnemonic, and it was used
  251.                                                             because the option (Disassemble_Extended) permits it.  The
  252.                                                             operand is formatted appropriate to the extended mnemonic.
  253.                                                             Whether the original basic form is placed in the comment or
  254.                                                             not is controlled by the Disassemble_BasicComm option.
  255.     **)
  256.     
  257.     
  258. (** All assembler options are of type DisassemblerOptions*:                                                                **)
  259.  
  260. TYPE
  261.     DisassemblerOptions* =    LONGINT;
  262.  
  263.     DisassemblerStatus* = INTEGER;                                (** disassembler return status (see above)    **)
  264.  
  265. (** The optional lookup function (NULL could be passed) is used to allow the caller to        **)
  266. (** substitute name strings for various objects that can occur in an operand.  It should    **)
  267. (** return a pointer to a non-null string if substitution is desired.  If NULL or a null **)
  268. (** string is returned, the disassembler uses its own default names.  The following            **)
  269. (** defines the possible substitable objects*:                                                                                        **)
  270.  
  271.     DisassemblerLookupType*    = SHORTINT; (*ΔΔ ( *)                                (** Types of substitutable objects*:                    **)
  272. CONST
  273.         Disassembler_Lookup_GPRegister* = 0; (*ΔΔ ,*)                    (**            general purpose register                        **)
  274.         Disassembler_Lookup_FPRegister* = 1; (*ΔΔ ,*)                    (**            floating point register                            **)
  275.         Disassembler_Lookup_UImmediate* = 2; (*ΔΔ ,*)                    (**            unsigned immediate value                        **)
  276.         Disassembler_Lookup_SImmediate* = 3; (*ΔΔ ,*)                    (**            signed (32-bit) immediate value            **)
  277.         Disassembler_Lookup_AbsAddress* = 4; (*ΔΔ ,*)                    (**            absolute addresse                                        **)
  278.         Disassembler_Lookup_RelAddress* = 5; (*ΔΔ ,*)                    (**            relocatable addresse                                **)
  279.         Disassembler_Lookup_RegOffset* = 6; (*ΔΔ ,*)                    (**            offset from a base register                    **)
  280.         Disassembler_Lookup_SPRegister* = 7; (*ΔΔ ,*)                    (**            special purpose register                        **)
  281.     (*ΔΔ );*)
  282. TYPE
  283.  
  284. (** Here's a definition of an object (value) which is a function of each                                 **)
  285. (** DisassemblerLookupType*:                                                                                                                            **)
  286.  
  287.     (* $ALIGN MAC68K*)
  288.     DisLookupValue* = LONGINT; (*ΔΔ RECORD                                        (** A "meaningful" name for each value type*:    **)
  289.         CASE INTEGER OF
  290.         0:    (gpr:                    LONGINT;);                        (**        Disassembler_Lookup_GPRegister                **)
  291.         1:    (fpr:                    LONGINT;);                        (**        Disassembler_Lookup_FPRegister                **)
  292.         2:    (ui:                    LONGINT;);                        (**        Disassembler_Lookup_UImmediate                **)
  293.         3:    (si:                    LONGINT;);                        (**        Disassembler_Lookup_SImmediate                **)
  294.         4:    (absAddress:    LONGINT;);                        (**        Disassembler_Lookup_AbsAddress                **)
  295.         5:    (relAddress:    LONGINT;);                        (**        Disassembler_Lookup_RelAddress                **)
  296.         6:    (spr:                    LONGINT;);                        (**         Disassembler_Lookup_SPRegister                **)
  297.         7:    (    (*    regOffset*)
  298.                     offset*:            INTEGER;
  299.                     baseReg*:        INTEGER;
  300.                 );                                                                    (**        Disassembler_Lookup_RegOffset                    **)
  301.     END;*)
  302.     (* $ALIGN RESET*)
  303.  
  304.     DisLookupValuePtr* = SYSTEM.PTR (*ΔΔ POINTER TO DisLookupValue*);
  305.  
  306. (** Finally, at long last, here's the definition of the disassembler...                                    **)
  307.  
  308. PROCEDURE ppcDisassembler*( VAR instruction     : LONGINT; 
  309.                                                             dstAdjust            :    LONGINT;
  310.                                                             options                :    DisassemblerOptions;
  311.                                                             mnemonic            :    Types.CStringPtr;
  312.                                                             operand                :    Types.CStringPtr;
  313.                                                             comment                :    Types.CStringPtr;
  314.                                                             refCon                : (*ΔΔUNIVΔΔ*) Types.Ptr;
  315.                                                             lookupRoutine    : (*ΔΔUNIVΔΔ*) Types.Ptr) : DisassemblerStatus; (*ΔΔC;ΔΔ*)
  316.     EXTERNAL (*•• C*);
  317.     (**
  318.     Takes the four bytes pointed to by instruction and disassembles it, placing the mnemonic,
  319.     operand, and comment in the strings provided.  The caller is then free to format or use
  320.     the output strings any way appropriate to the application.  Any of these strings may be a
  321.     null pointer, in which case that portion of the disassembled instruction is not returned.
  322.     If they are not null, it is ASSUMED that the associated buffers are large enough to hold
  323.     the disassembled output.
  324.     
  325.     Comments are formatted starting with a "; " (or "#" if the appropriate "IBM" option is
  326.     set).  Invalid instructions generate a "dc.l" (".long" for IBM), an operand of the form
  327.     0xXXXXXXXX showing the actual instruction, and a comment with a message indicating what
  328.     is wrong with the instruction.
  329.     
  330.     For PC-relative branches, the comment generated is the destination address, the only
  331.     address that the disassembler "knows" about is the address of the code pointed to by the
  332.     instruction.  Generally, that may be a buffer that has no relation to "reality", i.e.,
  333.     the actual code loaded into the buffer.  Therefore, to allow the address comment to be
  334.     mapped back to some actual address, the caller may specify an adjustment factor,
  335.     specified by dstAdjust that is ADDED to the value that normally would be placed in the
  336.     comment.
  337.  
  338.     Many operands usually consist of registers, absolute and relocatable addresses, and
  339.     signed and unsigned values.  In places where these occur, the disassembler can call a
  340.     user specified routine to do the substitution using the lookupRoutine parameter if it
  341.     is not NULL.  A "refcon" is passed to the disassembler that is, in turn, passed on to
  342.     the lookup routine to allow a communication path between the disassembler caller and its
  343.     lookup routine.  The refcon can be anything.  The disassembler does not look at it.
  344.     
  345.     The caller also can control some aspects of the formatting with the DisassemblerOptions
  346.     as described above.  The options also specify the target architecture; Power, PowerPC32,
  347.     PowerPC64, or PowerPC601.
  348.     
  349.     The disassembler returns as its function result the DisassemblerStatus.  This may be
  350.     tested for 0 ("false" or DisInvalid defined below) to find out if an invalid instruction
  351.     was detected.  For valid instructions, the DisassemblerStatus is non zero and indicates
  352.     various attributes about the instruction as follows*:                                                                    **)
  353.     
  354. (** The "lookup" substitution routine for the objects is defined as follows*:
  355.  
  356. PROCEDURE DisassemblerLookups*(            refCon                    :    (*ΔΔUNIVΔΔ*) Types.Ptr,
  357.                                                              VAR    cia                            :    LongInt, 
  358.                                                                     lookupType            :    DisassemblerLookupType,
  359.                                                                     thingToReplace    :    DisLookupValue) : CStringPtr; (*ΔΔC;ΔΔ*)
  360.     EXTERNAL (*•• C*);
  361.  
  362.     where, refCon*                  = A "reference constant" that can be used as a communication link
  363.                                                      between the lookup routine and the caller of the disassembler.
  364.                                                      It is the same refCon passed to the disassembler.
  365.  
  366.                     cia*                       = The instruction address passed to the disassembler.
  367.  
  368.                     lookupType and
  369.                     thingToReplace* = The kind of object and the associated value of that object to be
  370.                                                      replaced.  As defined by DisLookupValue, the thingToReplace has
  371.                                                      the following value for each lookupType.
  372.  
  373.                                                      lookupType                                                value            
  374.                                                      ============================================= 
  375.                                                      Disassembler_Lookup_GPRegister        0:31                
  376.                                                      Disassembler_Lookup_FPRegister        0:31                
  377.                                                      Disassembler_Lookup_UImmediate        integer    
  378.                                                      Disassembler_Lookup_SImmediate        integer        
  379.                                    Disassembler_Lookup_AbsAddress        address [1]
  380.                                                      Disassembler_Lookup_RelAddress        address [2]
  381.                                                      Disassembler_Lookup_RegOffset        D + Ra  [3]
  382.                                                      Disassembler_Lookup_SPRegister        spr            [4]
  383.                                                      =============================================
  384.  
  385.                                                       Notes*: 
  386.                                                      
  387.                                                      [1] This is an absolute target branch address, i.e., the "a" bit
  388.                                                               in the branch instruction IS set.  The passed absAddress
  389.                                                              is the address contained in the instruction.
  390.                                                              
  391.                                                      [2] This is a relocatable target branch address, i.e., the "a"
  392.                                                               bit in the branch instruction was NOT set.  The relAddress
  393.                                                              is relative to the current instruction address adjusted
  394.                                                              by the dstAdjust.  Thus,
  395.                                                              
  396.                                                              relAddress* = destinationAddress + dstAdjust + cia
  397.                                                              
  398.                                                              where cia is the current instruction address, i.e, the value
  399.                                                              of the instruction address passed to the disassembler.
  400.                                                                             
  401.                                                      [3] Both the offset (D) and base register (Ra) are passed.  The
  402.                                                               DisLookupValue.regOffset value defines how they are packed
  403.                                                              in the thingToReplace.  The offset should be assigned to a
  404.                                                              long to get its true 32-bit value.  It is valid to pass it
  405.                                                              as a signed short since the instruction field from which it
  406.                                                              came is never more than 16 bits wide.
  407.                                                      
  408.                                                      [4] The lookup for SPRs is slightly different in that it is only
  409.                                                               done as an ESCAPE mechanism, i.e., only when the SPR number is
  410.                                                              NOT one of the predefined Power, 601, PowerPC32, or
  411.                                                              PowerPC64 SPR names.  This is done because a different
  412.                                                              PowerPC architectures can have additional SPRs specific to
  413.                                                              those architectures!  The lookup routine is called only if
  414.                                                              the SPR is NOT one of the following predefined numbers*:
  415.                                                                     
  416.                                                                 0 MQ      272 SPRG0   528 IBAT0U   536 DBAT0U   1008 HID0
  417.                                                                 1 XER     273 SPRG1   529 IBAT0L   537 DBAT0L   1009 HID1
  418.                                                                 4 RTCU    274 SPRG2   530 IBAT1U   538 DBAT1U   1010 IABR
  419.                                                                 5 RTCL    275 SPRG3   531 IBAT1L   539 DBAT1L   1013 DABR
  420.                                                                 6 DEC     280 ASR     532 IBAT2U   540 DBAT2U   1023 PIR
  421.                                                                 8 LR      282 EAR     533 IBAT2L   541 DBAT2L
  422.                                                                 9 CTR     284 TB      534 IBAT3U   542 DBAT3U
  423.                                                              18 DSIAR   285 TBU     535 IBAT3L   543 DBAT3L
  424.                                                              19 DAR     287 PVR
  425.                                                              22 DEC
  426.                                                              25 SDR1
  427.                                                              26 SRR0
  428.                                                              27 SRR1
  429.                                                             
  430.                                                              Not all of these SPRs are valid for all targets.  The
  431.                                                              disassembler will check to see if these SPRs are valid for
  432.                                                              the specified target architecture.  If they are not, the SPR
  433.                                                              number is treated as an invalid field and processed
  434.                                                              according to the Disassemble_FieldErr option, i.e., it’s
  435.                                                              accepted but returns a status warning, or the instruction is
  436.                                                              treated as invalid (“DC.L 0xXXXXXXXX”).
  437.  
  438.                                                              SPR numbers which are not on the list, and also do not have
  439.                                                              a lookup substitution name, are always accepted.  But since
  440.                                                              there is no way for the disassembler to validate these
  441.                                                              against the target, the Disassembler_InvSprMaybe return
  442.                                                              status flag will be set.                                                                    **)
  443.                                                              
  444. (** NOTES*: 1. The disassembler library uses the convention that, with the exception of     **)
  445. (**                     the called routine name itself, i.e., "ppcDisassembler", all externally         **)
  446. (**                     visible names (linker symbols and macro names) begin with the letters "dis"**)
  447. (**                      (in any case).  The user should keep this in mind to avoid possible name     **)
  448. (**                      conflicts.                                                                                                                                    **)
  449.  
  450. (**                2. Except for statically declared (read only) tables, the disassembler uses no**)
  451. (**                     other global data.                                                                                                                    **)
  452.  
  453. (**                3. The disassembler is fully self contained in that it has no explicit                 **)
  454. (**                     references to any runtime library routines (e.g., strcpy).  There may,         **)
  455. (**                     however, be implicit references generated by the (C) compiler.                            **)
  456.  
  457. (**                4. The disassembler is written in standard ANSI C making it possible to easily**)
  458. (**                     port to other platforms.                                                                                                        **)
  459.  
  460.  
  461. (* $ALIGN RESET*)
  462. (* $POP*)
  463.  
  464.  END Disassembler.
  465.